use std::thread;
use std::thread::spawn;

fn takes_long_type(f: Box<dyn Fn() + Send + 'static>) {
}
fn returns_long_type() -> Box<dyn Fn() + Send + 'static> {
    Box::new(|| println!("hi"))
}
#[test]
fn test_long_type() {
    let f: Box<dyn Fn() + Send + 'static> = Box::new(|| println!("hi"));
}
type Thunk = Box<dyn Fn() + Send + 'static>;
fn takes_long_type_alias(f: Thunk) {
}
fn returns_long_type_alias() -> Thunk {
    Box::new(|| println!("hi"))
}
// pub trait Write{
//     fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error>;
//     fn flush(&mut self) -> Result<(), std::io::Error>;
//     fn write_all(&mut self, buf: &[u8]) -> Result<(), std::io::Error> ;
//     fn write_fmt(&mut self, fmt: std::fmt::Arguments<'_>) -> Result<(), std::io::Error> {
//         write!(self, "{}", fmt)
//     }
// }
//未声明别名前
type Result<T> =std::io::Result<T>;
//pub type Result<T> = result::Result<T, Error>; 这个io里面已经有一个别名了，将T,Error别名为T.
//间接使用io::Result<T>后，修改为：
pub trait Write{
    fn write(&mut self, buf: &[u8]) -> Result<usize>;
    fn flush(&mut self) -> Result<()>;
    fn write_all(&mut self, buf: &[u8]) -> Result<()> ;
    fn write_fmt(&mut self, fmt: std::fmt::Arguments<'_>) -> Result<()> {
        write!(self, "{}", fmt)
    }
}

#[test]
fn test_long_type_alias(){
    let f: Thunk = Box::new(|| println!("hi"));
    let b =thread::spawn(f);
    b.join().unwrap();
}
#[test]
fn test_alias(){
    type Meter = i32;
    let x:Meter = 10;
    let y= 5;
    assert_eq!(x+y,15);
    println!("x + y ={}",x+y);
}